﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using SCO.BE;
using SCO.DAO.Interfaces;
using System.Configuration;
namespace SCO.DAO.SqlDataAdapter
{
    public class HorarioDAO : IHorarioDAO
    {

        string cadenaConexion = string.Empty;
        public HorarioDAO()
        {
            this.cadenaConexion = ConfigurationManager.ConnectionStrings["CNX"].ConnectionString.ToString();
        }


        public List<horarioBE> listaDisponibilidad(horarioBE objeto)
        {
            horarioBE horario;
            List<horarioBE> lista = new List<horarioBE>();
            try
            {
                using (SqlConnection oCn = new SqlConnection(this.cadenaConexion))
                {
                    using (SqlCommand oCmd = new SqlCommand("UPS_LISTAR_DISPONIBILIDAD", oCn))
                    {
                        oCmd.Parameters.Add("@FECCITA", SqlDbType.VarChar, 20).Value = objeto.FECCITA;
                        oCmd.CommandType = CommandType.StoredProcedure;
                        oCmd.Connection = oCn;
                        oCn.Open();
                        SqlDataReader reader = oCmd.ExecuteReader();
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                horario = new horarioBE();
                                horario.CODHOR = reader.GetInt32(reader.GetOrdinal("CODHOR"));
                                horario.DESHOR = reader.GetString(reader.GetOrdinal("DESHOR"));
                                horario.CUP = reader.GetInt32(reader.GetOrdinal("CUP"));
                                horario.DESCUP = reader.GetString(reader.GetOrdinal("DESCUP"));
                                lista.Add(horario);
                            }
                            return lista;
                        }
                        else
                        {
                            return null;
                        }
                    }
                }
            }
            catch (Exception)
            {
                return null;
            }
        }
    }
}
